package de.justphil.tcg.tcgserver.commons.domain.containers;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import de.justphil.tcg.tcgserver.commons.config.GameConfig;
import de.justphil.tcg.tcgserver.commons.domain.Card;
import de.justphil.tcg.tcgserver.commons.domain.collections.CardInstanceCollection;

@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class NewGame implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 9148131992124696928L;
	
	
	@XmlElement(name="deckId")
	private long playerDeckId;
	
	
	private long gameId;
	private List<Long> playerIds;
	private CardInstanceCollection[] decks;
	private String[] otps;
	private Map<Long, Card> inGameCards;
	private Map<Long, Integer> playerToDeckMapping;
	private Map<Long, Integer> playerToOtpMapping;
	private String gameOtp;
	
	
	
	
	public NewGame() {
		// JAXB conformity
	}
	
	
	public void init() {
		playerIds = new ArrayList<Long>(GameConfig.NUMBER_OF_PLAYERS_PER_GAME);
		decks = new CardInstanceCollection[GameConfig.NUMBER_OF_PLAYERS_PER_GAME];
		
		for (int i = 0; i < decks.length; i++) {
			decks[i] = new CardInstanceCollection();
		}
		
		otps = new String[GameConfig.NUMBER_OF_PLAYERS_PER_GAME];
		inGameCards = new HashMap<Long, Card>();
		playerToDeckMapping = new HashMap<Long, Integer>(GameConfig.NUMBER_OF_PLAYERS_PER_GAME);
		playerToOtpMapping = new HashMap<Long, Integer>(GameConfig.NUMBER_OF_PLAYERS_PER_GAME);
	}
	
	

	public long getPlayerDeckId() {
		return playerDeckId;
	}
	
	public long getGameId() {
		return gameId;
	}




	public List<Long> getPlayerIds() {
		return playerIds;
	}




	public CardInstanceCollection[] getDecks() {
		return decks;
	}




	public Map<Long, Integer> getPlayerToDeckMapping() {
		return playerToDeckMapping;
	}




	public void setGameId(long gameId) {
		this.gameId = gameId;
	}




	public void setPlayerIds(List<Long> playerIds) {
		this.playerIds = playerIds;
	}




	public void setDecks(CardInstanceCollection[] decks) {
		this.decks = decks;
	}




	public void setPlayerToDeckMapping(Map<Long, Integer> playerToDeckMapping) {
		this.playerToDeckMapping = playerToDeckMapping;
	}
	
	
	public String[] getOtps() {
		return otps;
	}


	public Map<Long, Integer> getPlayerToOtpMapping() {
		return playerToOtpMapping;
	}


	public void setOtps(String[] otps) {
		this.otps = otps;
	}


	public void setPlayerToOtpMapping(Map<Long, Integer> playerToOtpMapping) {
		this.playerToOtpMapping = playerToOtpMapping;
	}


	public Map<Long, Card> getInGameCards() {
		return inGameCards;
	}


	public void setInGameCards(Map<Long, Card> inGameCards) {
		this.inGameCards = inGameCards;
	}


	public String getGameOtp() {
		return gameOtp;
	}


	public void setGameOtp(String gameOtp) {
		this.gameOtp = gameOtp;
	}
	
	
	
	
	/* ############################################################################################ */
	/* ############################################################################################ */
	/* ############################################################################################ */

	/*
	@Override
	public void readData(DataInput in) throws IOException {
		playerDeckId = in.readLong();
		gameId = in.readLong();
		
		int playerIdsSize = in.readInt();
		playerIds = new ArrayList<Long>(playerIdsSize);
		for (int i = 0; i < playerIdsSize; i++) {
			playerIds.add( new Long(in.readLong()) );
		}
		
		int decksLength = in.readInt();
		int listSize = 0;
		decks = new CardInstanceList[decksLength];
		CardInstanceList list = null;
		CardInstance ci = null;
		for(int i = 0; i < decksLength; i++) {
			listSize = in.readInt();
			list = new CardInstanceList(listSize);
			
			for (int j = 0; j < listSize; j++) {
				ci = new CardInstance();
				ci.readData(in);
				list.add(ci);
			}
			
			decks[i] = list;
		}
		
		int otpSize = in.readInt();
		otps = new String[otpSize];
		for (int i = 0; i < otpSize; i++) {
			otps[i] = in.readUTF();
		}
		
		int mappingSize = in.readInt();
		playerToDeckMapping = new HashMap<Long, Integer>();
		for(int i = 0; i < mappingSize; i++) {
			playerToDeckMapping.put(in.readLong(), in.readInt());
		}
		
		int otpMappingSize = in.readInt();
		playerToOtpMapping = new HashMap<Long, Integer>();
		for(int i = 0; i < otpMappingSize; i++) {
			playerToOtpMapping.put(in.readLong(), in.readInt());
		}
	}

	@Override
	public void writeData(DataOutput out) throws IOException {
		out.writeLong(playerDeckId);
		out.writeLong(gameId);
		
		out.writeInt(playerIds.size());
		for(Long l : playerIds) {
			out.writeLong(l.longValue());
		}
		
		out.writeInt(decks.length);
		for(int i = 0; i < decks.length; i++) {
			out.writeInt(decks[i].size());
			
			for (CardInstance ci : decks[i].getList()) {
				ci.writeData(out);
			}
		}
		
		out.writeInt(otps.length);
		for (int i = 0; i < otps.length; i++) {
			out.writeUTF(otps[i]);
		}
		
		out.writeInt(playerToDeckMapping.size());
		for (Long l : playerToDeckMapping.keySet()) {
			out.writeLong(l.longValue());
			out.writeInt(playerToDeckMapping.get(l).intValue());
		}
		
		out.writeInt(playerToOtpMapping.size());
		for (Long l : playerToOtpMapping.keySet()) {
			out.writeLong(l.longValue());
			out.writeInt(playerToOtpMapping.get(l).intValue());
		}
	}
	*/
	
}
